const path = require('path')
// const {applyMock} = require("./build/mock")
const pkg = require('./package.json')
const webpack = require('webpack')
module.exports = {
  // assetsDir: './static',
  publicPath: process.env.VUE_APP_BASEURL || '/',
  // outputDir: process.env.VUE_APP_BASEURL || 'dist/',
  productionSourceMap: false,
  chainWebpack: chain => {
    if (pkg && pkg.version) {
      chain.plugin('define').tap(([options]) => {
        options['process.env']['VUE_APP_NAME'] = `"${pkg.name}"`
        options['process.env']['VUE_APP_VERSION'] = `"${pkg.version}"`
        return [options]
      })
    }

    chain.module.rule('svg').include.add(path.resolve(__dirname, './src/icons'))
    chain.module.rule('svg').uses.delete('file-loader')
    chain.module
      .rule('svg')
      .test(/\.(svg)(\?.*)?$/)
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })

    chain.module
      .rule('images')
      .use('url-loader')
      .loader('url-loader')
      .tap(options => {
        options.limit = 1
        return options
      })
    // .options({
    //   limit: inlineLimit,
    //   name: `img/[name].[hash:8].[ext]`
    // })
  },
  configureWebpack: function(config) {
    // console.log(config.module.rules[2])
    return {
      plugins: [
        new webpack.ProvidePlugin({
          $: 'jquery',
          jQuery: 'jquery',
          'windows.jQuery': 'jquery'
        })
      ],
      resolve: {
        // extensions: ['.js', '.json'],
        alias: {
          '@': path.resolve(__dirname, './src'),
          echarts: path.resolve(
            __dirname,
            './node_modules/echarts/dist/echarts.min.js'
          ),
          '@cui-components': path.resolve(
            __dirname,
            './src/cui-components/packages'
          )
        }
      }
    }
  },
  // devServer 选项单独配置
  devServer: {
    https: false,
    port: 9090,
    proxy: {
      '/v1': {
        target: process.env.VUE_APP_API_URL,
        changeOrigin: true
      },
      '/get_token_by_code': {
        target: process.env.VUE_APP_API_URL,
        changeOrigin: true
      },
      '/qcloud': {
        target: process.env.VUE_APP_API_URL,
        changeOrigin: true
      }
    },
    before: app => {
      // applyMock(app)
    }
  }
}
